home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
SSGame.as
< prev
next >
Wrap
Text File
|
2006-11-29
|
14KB
|
449 lines
class SSGame extends GDK.Base
{
static var _sinit = SSGame.staticInit();
static var levels = [];
static var styles = [];
static var backgrounds = [];
static var processStack = new CallStack();
static var running = false;
static var ready = false;
static var currentLevel = 0;
function SSGame()
{
super();
SSInterface.registerGame(this);
GDK.EventSubscriber.initObject(SSGame);
SSGame.setTargetComponent(this);
SSGame.classes = [];
SSGame.registerClass(SSShape);
SSGame.registerClass(SSZone);
SSGame.registerClass(GameSpring);
SSGame.registerClass(GamePoint);
SSGame.registerClass(GameHealth);
SSGame.registerClass(GameCharacter);
SSGame.registerClass(Explosive);
SSGame.registerClass(Checkpoint);
SSGame.registerClass(CommandBox);
SSGame.registerClass(DirectionArrow);
SSGame.registerClass(GameElement);
SSGame.registerClass(Spikes);
SSGame.registerClass(GameLife);
SSGame.registerClass(GameVehicle);
SSGame.registerClass(WalkingObject);
SSGame.registerClass(FlyingObject);
SSGame.registerClass(RopeObject);
SSGame.registerClass(GameContainer);
SSGame.registerClass(GameBigPoint);
SSGame.registerClass(GameHealthBig);
SSGame.registerClass(RollingObject);
SSGame.registerClass(FlyingObject);
SSGame.registerClass(BouncingObject);
SSGame.registerClass(JumpingFish);
SSGame.registerClass(GameFuel);
SSGame.registerClass(GameSwing);
SSGame.registerClass(VR_HiddenPlatform);
SSGame.registerClass(VR_EMP);
SSGame.registerClass(VR_Shield);
SSGame.registerClass(MessageBox);
SSGame.registerClass(SSDrawStyle);
this.addEvent("Pause",this.onGamePause);
this.addEvent("Resume",this.onGameResume);
this.baseSound = new Sound(this);
}
static function setTargetComponent(mc)
{
SSGame.target = mc;
}
static function staticInit()
{
SSGame.processStack.wait(0.1);
}
static function registerClass(cls)
{
var _loc1_ = GDK.Tools.lookupClassName(cls);
if(_loc1_ == null)
{
return undefined;
}
if(SSGame.classes[_loc1_])
{
return undefined;
}
cls.className = _loc1_;
SSGame.classes.push(SSGame.classes[_loc1_] = _loc1_);
}
static function loadConfig(url)
{
SSGame.processStack.wait(0.01);
var _loc2_ = new XML();
_loc2_.ignoreWhite = true;
_loc2_.onLoad = function()
{
this.loaded = true;
};
_loc2_.loaded = false;
SSGame.processStack.call(SSGame,function(x, url)
{
x.load(url);
}
,_loc2_,url);
SSGame.processStack.call(_loc2_,function()
{
return this.loaded == true;
}
);
SSGame.processStack.call(SSGame,SSGame.processConfig,_loc2_);
}
static function processConfig(data)
{
if(typeof data == "string")
{
data = new XML(data);
}
var _loc2_ = undefined;
var _loc1_ = -1;
var _loc3_ = _loc2_ = data.firstChild.childNodes.length;
while((_loc1_ = _loc1_ + 1) < _loc3_)
{
switch(_loc2_[_loc1_].nodeName.toLowerCase())
{
case "styles":
SSGame.processStyles(_loc2_[_loc1_]);
break;
case "bg":
SSGame.processBackgrounds(_loc2_[_loc1_]);
break;
case "objects":
SSGame.processObjects(_loc2_[_loc1_]);
}
}
}
static function processBackgrounds(data)
{
if(typeof data == "string")
{
data = new XML(data);
}
var _loc13_ = undefined;
var _loc16_ = data.firstChild;
if(!_loc16_)
{
return undefined;
}
var _loc18_ = undefined;
var _loc15_ = undefined;
var _loc20_ = undefined;
var _loc3_ = undefined;
var _loc17_ = undefined;
var _loc19_ = undefined;
var _loc11_ = undefined;
do
{
var _loc0_ = null;
var _loc21_ = _global[_loc16_.attributes.name] = {layers:_loc20_ = []};
_loc15_ = _loc18_ = _loc16_.childNodes.length;
while((_loc15_ = _loc15_ - 1) > -1)
{
_loc3_ = _loc18_[_loc15_].attributes;
if(!(!_loc17_ = _loc3_.tiles.length || !(_loc19_ = Number(_loc3_.z))))
{
var _loc9_ = Number(_loc3_.w);
var _loc12_ = Number(_loc3_.h);
if(!_loc9_ || !_loc12_)
{
var _loc7_ = _global.root.attachMovie(_loc17_,"TMPBGTEST",987700);
if(!_loc7_)
{
continue;
}
_loc9_ = _loc7_._width;
_loc12_ = _loc7_._height;
_loc7_.removeMovieClip();
}
_loc20_.push(_loc11_ = new SSBackground(_loc17_,_loc19_,_loc9_,_loc12_,Number(_loc3_.scrollMultiplier)));
if(!isNaN(_loc13_ = Number(_loc3_.offsetX)))
{
_loc11_.offsetX = _loc13_;
}
if(!isNaN(_loc13_ = Number(_loc3_.offsetY)))
{
_loc11_.offsetY = _loc13_;
}
_loc11_.stationary = Number(_loc3_.stationary) || _loc3_.stationary == "true" || _loc3_.stationary == "yes";
var _loc14_ = _loc18_[_loc15_].firstChild.nodeValue;
var _loc10_ = GDK.Tools.trim;
if(_loc14_.length > 0)
{
var _loc4_ = undefined;
var _loc6_ = undefined;
var _loc2_ = _loc14_.split("|");
_loc9_ = 0;
var _loc5_ = _loc2_.length;
while((_loc5_ = _loc5_ - 1) > -1)
{
if(!_loc2_[_loc5_] = _loc10_(_loc2_[_loc5_]).length)
{
_loc2_.splice(_loc5_,1);
}
else
{
_loc2_[_loc5_] = _loc2_[_loc5_].split(",");
_loc4_ = _loc6_ = _loc2_[_loc5_].length;
_loc9_ = Math.max(_loc4_,_loc9_);
while((_loc4_ = _loc4_ - 1) > -1)
{
_loc6_[_loc4_] = parseInt(_loc10_(_loc6_[_loc4_]));
}
}
}
var _loc8_ = new GDK.Grid(_loc9_,_loc2_.length,!Number(_loc3_.defaultCell) ? 0 : Number(_loc3_.defaultCell));
_loc5_ = _loc2_.length;
while((_loc5_ = _loc5_ - 1) > -1)
{
_loc4_ = _loc2_[_loc5_].length;
while((_loc4_ = _loc4_ - 1) > -1)
{
_loc8_.setCell(_loc4_,_loc5_,_loc2_[_loc5_][_loc4_]);
}
}
_loc11_.setPattern(_loc8_);
}
}
}
}
while(_loc16_ = _loc16_.nextSibling);
}
static function processObjects(data)
{
if(typeof data == "string")
{
data = new XML(data);
}
var _loc1_ = data.firstChild;
if(!_loc1_)
{
return undefined;
}
var _loc3_ = undefined;
while(_loc1_ = _loc1_.nextSibling)
{
}
}
static function processStyles(data)
{
if(typeof data == "string")
{
data = new XML(data);
}
var _loc7_ = data.firstChild;
if(!_loc7_)
{
return undefined;
}
var _loc8_ = undefined;
do
{
_loc8_ = _loc7_.attributes;
if(_loc8_.name != null)
{
var _loc0_ = null;
var _loc9_ = _global[_loc8_.name] = function()
{
var _loc3_ = [];
var _loc2_ = this.__proto__;
while(_loc2_ = _loc2_.__proto__)
{
_loc3_.push(_loc2_);
}
var _loc4_ = _loc3_.length;
while((_loc4_ = _loc4_ - 1) > -1)
{
_loc3_[_loc4_].constructor.apply(this);
}
};
var _loc5_ = _loc9_.prototype;
_loc5_.__proto__ = _global[_loc8_.using].prototype;
if(_loc5_.__proto__ == null)
{
_loc5_.__proto__ = SSDrawStyle.prototype;
}
_loc5_.className = _loc8_.name;
_loc5_.styleXML = _loc7_;
}
}
while(_loc7_ = _loc7_.nextSibling);
}
static function loadLevel(url)
{
var _loc3_ = -1;
var _loc4_ = arguments.length;
while((_loc3_ = _loc3_ + 1) < _loc4_)
{
var _loc2_ = new XML();
_loc2_.ignoreWhite = true;
var lev = new SSLevel();
SSGame.processStack.call(SSGame,function(data, url)
{
data.load(url);
}
,_loc2_,arguments[_loc3_]);
SSGame.processStack.waitUntilEqual(_loc2_,"loaded",true);
SSGame.processStack.call(lev,lev.readXML,_loc2_);
SSGame.processStack.waitUntilEqual(lev,"ready",true);
SSGame.processStack.call(SSGame,function()
{
SSGame.levels.push(SSGame.levels[lev.name] = lev);
}
,lev);
}
}
static function processLevel(data)
{
var lev = new SSLevel();
if(typeof data == "string")
{
data = new XML(data);
}
SSGame.processStack.call(lev,lev.readXML,data);
SSGame.processStack.waitUntilEqual(lev,"ready",true);
SSGame.processStack.call(SSGame,function()
{
SSGame.levels.push(SSGame.levels[lev.name] = lev);
}
,lev);
}
static function processStyle(data)
{
}
static function processBackground(data)
{
}
static function process()
{
if(SSGame.running)
{
return undefined;
}
SSGame.running = true;
SSGame.processStack.onFinish = function()
{
SSGame.ready = true;
SSGame.onReady();
};
SSGame.processStack.start();
delete SSGame.process;
}
function gotoWorld(name, targetNode, char)
{
var _loc2_ = this.worlds[name];
if(_loc2_)
{
if(_loc2_ != this.activeWorld)
{
}
}
else
{
this.generateWorld(name,targetNode,char);
}
}
function generateWorld(name, targetNode, char)
{
_global.root.levelIntro.show(SSGame.currentLevel);
var _loc4_ = SSGame.levels[String(name)];
_loc4_.targetNode = targetNode;
_loc4_.char = char;
_loc4_.onComplete = function(base, ssw)
{
var _loc3_ = new GameCharacter();
_loc3_.keepInScene = false;
ssw.addObject(ssw.character = _loc3_);
ssw.addPlayer(SSGame.player);
if(ssw.references[this.targetNode] != null)
{
_loc3_.setRestorePoint(ssw.references[this.targetNode]);
_loc3_.restore();
}
base.setActiveWorld(ssw);
SSGame.player.setControl(_loc3_);
SSInterface.watchObject(SSGame.player,function(obj)
{
this.watchProp(SSGame,"currentLevel",function(prop, oldValue, newValue)
{
SSInterface.target[prop] = newValue + 1;
return newValue;
}
);
this.watchProp(obj,"score",this.textValue);
this.watchProp(obj,"lives",this.textValue);
this.watchProp(obj,"fuel",this.meterValue);
this.watchProp(obj,"shield",this.textValue);
this.watchProp(obj,"health",this.meterValue);
}
);
GameSound.playMusic(this.music,0.5,true);
base.start();
SSInterface.hide();
_global.root.levelIntro.hide();
};
_loc4_.build(this);
}
function addMaterial()
{
}
function addShapeStyle()
{
}
static function startNewGame()
{
SSGame.player = new GamePlayer();
SSInterface.hide();
SSGame.currentLevel = 0;
if(Key.isDown(17))
{
if(Key.isDown(50))
{
SSGame.currentLevel = 1;
}
else if(Key.isDown(51))
{
SSGame.currentLevel = 2;
}
}
SSGame.target.activeWorld = null;
SSGame.target.removeAllWorlds();
SSGame.target.gotoWorld(SSGame.levels[SSGame.currentLevel].name,SSGame.levels[SSGame.currentLevel].startNode);
}
static function nextLevel()
{
if(++SSGame.currentLevel >= SSGame.levels.length)
{
SSGame.winGame();
SSGame.target.removeAllWorlds();
return undefined;
}
_global.root.gotoAndStop("cacheLoad");
var _loc2_ = SSGame.target.activeWorld.character;
SSGame.target.gotoWorld(SSGame.levels[SSGame.currentLevel].name,SSGame.levels[SSGame.currentLevel].startNode,_loc2_);
}
static function exitLevel()
{
}
static function winGame()
{
SSInterface.showScreen("WinGame",true);
}
function onGamePause()
{
this.baseSound.setVolume(0);
GameSound.pause();
}
function onGameResume()
{
this.baseSound.setVolume(100);
GameSound.resume();
}
}